﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SWEN_HMS.Classes;

namespace SWEN_HMS.UserModule
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                EncodingAndDecodingcs en = new EncodingAndDecodingcs();
                int staffId = Convert.ToInt32(tbxStaffID.Text);
                string password = tbxPW.Text;
                string access = userDB.login(staffId, password);

                staff s = userDB.getDetailByStaffID(staffId);
                string accessLvl = s.accessLevel;


                if (access != null)
                {
                    Session.Add("staffid", staffId);
                    Session.Add("PW", en.Encode(password));
                    Session.Add("access", access);
                    Session.Add("accessLvl", accessLvl);
                    Response.Redirect("~/BookingModule/RoomAvailability.aspx");

                }
                else
                {
                    lblerror.Text = "Invalid ID or Password";
                }
            }
            catch
            {
                lblerror.Text = "Invalid ID or Password";
            }

        }

     
    }
}